<?php

class Storage
{
  public function __construct($namespace = 'default')
  {
    $this->path = sys_get_temp_dir() . '/' . $namespace;
    if(!is_dir($this->path)) {
      mkdir($this->path,0777);
    }
  }
  
  public function get($name, $default = null)
  {
    $fileName = $this->path . '/' . md5($name);
    if(file_exists($fileName)) {
      return unserialize(file_get_contents($fileName));
    }
    
    return $default;
  }
  
  public function set($name, $value)
  {
    $fileName = $this->path . '/' . md5($name);
    file_put_contents($fileName,  serialize($value));
  }
  
  public function remove($name)
  {
    $fileName = $this->path . '/' . md5($name);
    if(file_exists($fileName)) {
      unlink($fileName);
    }
  }
}